#ifndef XABSTRACTSYNTAXTREEN_H
#define XABSTRACTSYNTAXTREEN_H
#include <xscript/xabstractsyntaxtree.h>
#include <xscript/xscriptexecutor.h>

template<int N>
class XAbstractSyntaxTreeN : public XAbstractSyntaxTree
{
  public:
    XAbstractSyntaxTreeN(XTokenPtr token):
        XAbstractSyntaxTree(token)
    {}
    virtual ~XAbstractSyntaxTreeN() = default;
  public:
    bool invoke(std::shared_ptr<XVariableTable> table)override
    {
        if(getChildCount() != N)
        {
            XScriptExecutor::getInstance()->setError(XError::XError_ArgumentCountError,token->toString());
            return false;
        }
        return invokeImpl(table);
    }
    bool isFilled()const override{return children.size() == 2;}
protected:  
    virtual bool invokeImpl(std::shared_ptr<XVariableTable> table) = 0;
  protected:
    XTokenPtr token;
    XItemPtr result;
};

#endif // XABSTRACTSYNTAXTREEN_H
